﻿<!--***********************************************************************************

   Extended WPF Toolkit

   Copyright (C) 2007-2013 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   For more features, controls, and fast professional support,
   pick up the Plus Edition at http://xceed.com/wpf_toolkit

   Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids

  **********************************************************************************-->

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:local="clr-namespace:Xceed.Wpf.Toolkit"
                    xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes"
                    xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes"
                    xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="../../Themes/Aero2/Common.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <conv:InverseBoolConverter x:Key="InverseBoolConverter" />

    <DataTemplate x:Key="DefaultWatermarkTemplate">
        <ContentControl Content="{Binding}" Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" Focusable="False" Margin="0,0,3,0" />
    </DataTemplate>

    <Style x:Key="DateTimePickerToggleButtonStyle" TargetType="ToggleButton">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Grid SnapsToDevicePixels="True">
                        <chrome:ButtonChrome x:Name="ToggleButtonChrome"
                                       CornerRadius="0"
                                       RenderChecked="{Binding IsOpen, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:DateTimePicker}}"
                                       RenderEnabled="{Binding IsEnabled, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:DateTimePicker}}"
									   RenderMouseOver="{TemplateBinding IsMouseOver}"
									   RenderPressed="{TemplateBinding IsPressed}">

                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                                <Grid x:Name="arrowGlyph" IsHitTestVisible="False" Grid.Column="1" Margin="5">
                                    <Path x:Name="Arrow" Width="7" Height="4" Data="M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z" Fill="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
                                </Grid>
                            </Grid>
                        </chrome:ButtonChrome>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Fill" TargetName="Arrow" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <!-- =============================================================================== -->
    <!-- DateTimePicker                                                                  -->
    <!-- =============================================================================== -->

    <Style TargetType="{x:Type local:DateTimePicker}">
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
        <Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlNormalBorderKey}}" />
        <Setter Property="BorderThickness" Value="1,1,0,1" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="HorizontalContentAlignment" Value="Right" />
        <Setter Property="TextAlignment" Value="Right" />
        <Setter Property="TimeWatermarkTemplate" Value="{StaticResource DefaultWatermarkTemplate}" />
        <Setter Property="WatermarkTemplate" Value="{StaticResource DefaultWatermarkTemplate}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:DateTimePicker}">
                    <Border>
                        <Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <local:ButtonSpinner x:Name="PART_Spinner"
                                             IsTabStop="False"
                                             Background="{TemplateBinding Background}"
                                             BorderThickness="{TemplateBinding BorderThickness}"
                                             BorderBrush="{TemplateBinding BorderBrush}"
                                             AllowSpin="{TemplateBinding AllowSpin}"
                                             ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}">
                                    <local:WatermarkTextBox x:Name="PART_TextBox"
                                                   BorderThickness="0" 
                                                   Background="Transparent"
                                                   FontFamily="{TemplateBinding FontFamily}" 
                                                   FontSize="{TemplateBinding FontSize}" 
                                                   FontStretch="{TemplateBinding FontStretch}"
                                                   FontStyle="{TemplateBinding FontStyle}" 
                                                   FontWeight="{TemplateBinding FontWeight}" 
                                                   Foreground="{TemplateBinding Foreground}" 
                                                   HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                   IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
                                                   MinWidth="20"
                                                   AcceptsReturn="False"
                                                   Padding="0"
                                                   TextAlignment="{TemplateBinding TextAlignment}"
                                                   TextWrapping="NoWrap" 
                                                   Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}"
                                                   TabIndex="{TemplateBinding TabIndex}"
                                                   Watermark="{TemplateBinding Watermark}"
                                                   WatermarkTemplate="{TemplateBinding WatermarkTemplate}" />
                                </local:ButtonSpinner>
                                <ToggleButton x:Name="_calendarToggleButton"
                                      Grid.Column="1"
                                      Background="White"
                                      Focusable="False"
                                      IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}}"
                                      Style="{StaticResource DateTimePickerToggleButtonStyle}"
                                      IsHitTestVisible="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}}"
                                      IsEnabled="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}}" />
                            </Grid>
                            <Popup x:Name="PART_Popup" IsOpen="{Binding IsChecked, ElementName=_calendarToggleButton}" StaysOpen="False">
                                <Border BorderThickness="1" Background="{StaticResource PanelBackgroundBrush}" BorderBrush="{StaticResource PopupDarkBorderBrush}" Padding="3">
                                    <StackPanel>
                                        <Calendar x:Name="PART_Calendar" BorderThickness="0" />
                                        <local:TimePicker x:Name="PART_TimeUpDown"
                                                Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                                                Foreground="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" 
                                                Format="{TemplateBinding TimeFormat}"
                                                FormatString="{TemplateBinding TimeFormatString}"
                                                Value="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}"
                                                Minimum="{Binding Minimum, RelativeSource={RelativeSource TemplatedParent}}"
                                                Maximum="{Binding Maximum, RelativeSource={RelativeSource TemplatedParent}}"
                                                ClipValueToMinMax="{Binding ClipValueToMinMax, RelativeSource={RelativeSource TemplatedParent}}"
                                                Watermark="{TemplateBinding TimeWatermark}"
                                                WatermarkTemplate="{TemplateBinding TimeWatermarkTemplate}" />
                                    </StackPanel>
                                </Border>
                            </Popup>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlMouseOverBorderKey}}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlSelectedBorderKey}}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter TargetName="PART_TextBox" Property="FocusManager.FocusedElement" Value="{Binding ElementName=PART_TextBox}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
